//
// Created by xili on 2024/9/21 10:41.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int jump(vector<int> &nums) {
        int ans = 0;
        int end = 0;
        int maxPos = 0;
        for (int i = 0; i < nums.size() - 1; i++) {
            maxPos = max(nums[i] + i, maxPos);
            if (i == end) {
                end = maxPos;
                ans++;
            }
        }
        return ans;
    }
};